<template>
  <el-config-provider v-if="loaded" :locale="lang[language]" namespace="el" :size="size">
    <router-view />
  </el-config-provider>
</template>
<script setup lang="ts">
import { onMounted } from 'vue'
//element-plus lang
import zh from 'element-plus/dist/locale/zh-cn.mjs'
import en from 'element-plus/dist/locale/en.mjs'
import { storeToRefs } from 'pinia/dist/pinia'
import { useRoute } from 'vue-router'
import { projectInfoCheck } from '@/api/project-info'
import { useBasicStore } from '@/store/basic'
import { useConfigStore } from '@/store/config'
import { useErrorLog } from '@/hooks/use-error-log'
import { useProjectInfoStore } from '@/store/projectInfo'
//reshow default setting
import { toggleHtmlClass } from '@/theme/utils'
const lang = { zh, en }

const { size, language } = storeToRefs(useConfigStore())
const { setProjectInfo } = useProjectInfoStore()

const route = useRoute()
onMounted(async () => {
  useErrorLog()
  const { setTheme, theme, setLanguage, language } = useConfigStore()
  setTheme(theme)
  setLanguage(language, route.meta?.title)
  toggleHtmlClass(theme)
  await setInfo()
})
const { setTokenAndInfo } = useBasicStore()
const loaded = ref(false)
const setInfo = async () => {
  if (window.name === '') return
  const head = JSON.parse(window.name)
  // 代理系统 （带项目查询信息）
  setTokenAndInfo(head)
  if (head.projectInfo) {
    try {
      loaded.value = false
      const res: any = await projectInfoCheck(head.projectInfo)
      await setProjectInfo(res)
      loaded.value = true
    } catch (error) {
      loaded.value = true
      console.log('🐷 🐽 setInfo 🐽 error👉👉👉', error)
    }
  } else {
    loaded.value = true
  }
}
</script>
<style lang="scss">
//修改进度条样式
#nprogress .bar {
  background: var(--pregress-bar-color) !important;
}
</style>
